#!/bin/bash
path1=`pwd`
jarbag1=`ls $path1 | grep 'jar'`
program1=`echo ${jarbag1%-*}`
program2=$(echo $program1 | tr '[A-Z]' '[a-z]')
docker1=/usr/bin/docker
containerid1=`$docker1 ps -a | grep $program1 | awk -F' ' '{print $1}'`
imageid=`$docker1 images | grep $program1 | awk -F' ' '{print $3}'`
#
if [ "$containerid1" != "" ];then
    $docker1 rm -f $containerid1
fi
#
if [ "$imageid" != "" ];then
    $docker1 rmi -f $imageid
fi
#
if [ -f ${path1}/Dockerfile ];then
    echo "" > ${path1}/Dockerfile
else
    touch ${path1}/Dockerfile
fi
#
tee ${path1}/Dockerfile <<-EOF
FROM 10.30.49.177:5000/java
MAINTAINER chengcheng
RUN mkdir -p /usr/local/pinpoint-agent
RUN echo 'Asia/Shanghai' > /etc/timezone
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ADD ${jarbag1} app.jar
ENTRYPOINT ["java","-javaagent:/usr/local/pinpoint-agent/pinpoint-bootstrap-1.6.0.jar","-Dpinpoint.agentId=Test","-Dpinpoint.applicationName=${program1}-Test","-jar","/app.jar"]
EOF
#

$docker1 build -t `date +%Y%m%d`/${program2} ${path1}
$docker1 run -d --net=host -v /usr/local/pinpoint-agent:/usr/local/pinpoint-agent `date +%Y%m%d`/${program2}
#$docker1 run -d --net=host `date +%Y%m%d`/${program2}

